from api.jiuchao_emp_api import JCEmpApi
from common.assert_tools import common_assert
from common.get_header import get_header
from common.py09_db_tools import DBTools
from config import TEL


class TestAddEmp(object):
    req_header = None

    def setup_class(self):
        self.req_header = get_header()

    def setup(self):
        del_sql = f"delete from system_users where mobile = '{TEL}';"
        DBTools.db_uid(del_sql)

    def teardown(self):
        del_sql = f"delete from system_users where mobile = '{TEL}';"
        DBTools.db_uid(del_sql)

    # 定义测试方法  -添加成功用例
    def test01_add_ok(self):
        # 调用自己封装的api，发送请求
        json = {"nickname": "测试899", "deptId": "", "mobile": TEL, "email": "", "username": "ceshi1111",
                "password": "123456", "postIds": [], "remark": "", "status": 0, "roleIds": []}
        res = JCEmpApi.add_emp(self.req_header, json)
        print("必选参数添加成功:", res.json())
        # 调用之前封装的断言
        common_assert(res, 200, 0, "")

    # 定义测试方法-添加成功所有参数
    def test02_username_none(self):
        # 调用自己封装的api，发送请求
        json = {"nickname": "测试899", "deptId": "", "mobile": TEL, "email": "", "username": None,
                "password": "123456", "postIds": [], "remark": "", "status": 0, "roleIds": []}
        res = JCEmpApi.add_emp(self.req_header, json)
        print("用户名为空:", res.json())
        # 调用之前封装的断言
        common_assert(res, 200, 400, "请求参数不正确:用户账号不能为空")

    # 定义测试方法-添加成功所有参数
    def test03_pwd_none(self):
        # 调用自己封装的api，发送请求
        json = {"nickname": "测试899", "deptId": "", "mobile": TEL, "email": "", "username": "ceshi1111",
                "password": None, "postIds": [], "remark": "", "status": 0, "roleIds": []}
        res = JCEmpApi.add_emp(self.req_header, json)
        print("密码为空:", res.json())
        # 调用之前封装的断言
        common_assert(res, 200, 400, "请求参数不正确:密码不能为空")
